<?php
namespace backend\controllers;


use Yii;
use yii\web\Controller;
use backend\models\AdminModel;

class AdminloginController extends Controller
{
	public $enableCsrfValidation = false;
	public $layout=false;
/**
 * @inheritdoc
*/
	public function actions()
	{
	    return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => null,
            ],
        ];
	}
	public function actionIndex()
	{
		$model=new AdminModel();
		 if($posts=Yii::$app->request->post())
		 {
			$q=AdminModel::find();
			$u=$q->where('admin_user=:status', [':status' => $posts['admin_user']])->one();			 
			if($u)
			{
				$pwd=$q->where('admin_pwd=:status', [':status' => $posts['admin_pwd']])->one();	
				if($pwd)
				{
					$data['error']=0;
					$data['msg']="登陆成功！";
					$session=Yii::$app->session;
					if($posts['remem_pw']=='1')
					{
						$session['content']=array(
							'name'=>$posts['admin_user'],
							'lefttime'=>3600*365*24,
							'id'=>$pwd['admin_id'],
							'sessionid'=>md5(sha1($posts['admin_user']).time().rand())
							);						
					}
					else if($posts['remem_pw']=='0')
					{
					$session['content']=array(
						'name'=>$posts['admin_user'],
						'lefttime'=>3600*1*24,
						'id'=>$pwd['admin_id'],
						'sessionid'=>md5(sha1($posts['admin_user']).time().rand())
						);							
					}
				}
				else
				{
					$data['error']=1;
					$data['msg']="用户名或密码失败！";
				}
			}
			else
			{
				$data['error']=1;
				$data['msg']="用户名或密码失败！";
			}
			echo json_encode($data);
		 	// $data=Yii::$app->db->createCommand("SELECT * FROM `seven_admin` WHERE admin_user='root'")->queryOne();
			// print_r($data);
		 }
		 else
		 {
		 	return $this->render('index',['model'=>$model]);			
		 }
	}

}
